#!/bin/bash




:<<EOF

按时间还原点发送北部湾商户数据, 必须先确认已经跑了  北部湾历史商户数据  rerun_bbw_mer_history.sh    ;

    bash    export_bbw_data_historical_V2.sh    -s   2024-08-01   -e  2025-08-20 -f

EOF



BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
cd $BASE_DIR || exit;

shopt -s expand_aliases
[ "$(uname)" == "Darwin" ] &&  alias date='gdate'

ENV="prod"
DRY_RUN_ARG=""
FORCE_EXPORT_ARG=""
START_DATE="2024-08-01"
END_DATE="2024-08-18"
#END_DATE=$(date -d "yesterday" +%Y-%m-%d)

while getopts "Dfs:e:" opt; do
    case ${opt} in
    s )
        START_DATE="$OPTARG"
        ;;
    e )
        END_DATE="$OPTARG"
        ;;
    D )
        DRY_RUN_ARG="-D"
        ;;
    f )
        FORCE_EXPORT_ARG="-f"
        ;;
    *)
        echo "Invalid option: $opt requires an argument" 1>&2
        ;;
    esac
done
shift $((OPTIND -1))

start=$START_DATE
end=$END_DATE
while ! [[ $start > $end ]]; do
    echo [`date`] exporting $start
    DATE="$start"

    bash   ./bin/export_bbw_data_V2.sh -e prod -t $DATE $DRY_RUN_ARG $FORCE_EXPORT_ARG

    start=$(date -d "$start + 1 day" +%F)
done
